require('../css/common/normalize.css')
require('../css/common/reset.css')
require('../css/common/property.css')
require('../css/common/basic.less')
require('../lib/fonts/iconfont.css')
require('../css/login.less')

//验证码插件

const CaptchaMini = require("captcha-mini")

//axios
const axios = require('axios')

// meui 库
require('weui')
const weui = require("weui.js")


document.addEventListener('DOMContentLoaded',function(){

    /*  
    获取元素：
*/

const loginPhone=document.querySelector('#login-phone')
const loginYanzheng=document.querySelector('#login-yanzheng')
const loginPwd=document.querySelector('#login-pwd')
const loginPwd2=document.querySelector('#login-pwd2')
const loginBtn=document.querySelector('#login-btn')
const judge=document.querySelector('.judge')


let count=''
let captcha2 = new CaptchaMini({
    lineWidth: 1,   //线条宽度
    lineNum: 2,       //线条数量
    dotR: 2,          //点的半径
    dotNum: 25,       //点的数量
    preGroundColor: [10, 80],    //前景色区间
    backGroundColor: [150, 250], //背景色区间
    fontSize: 45,           //字体大小
    fontFamily: ['Georgia', '微软雅黑', 'Helvetica', 'Arial'],  //字体类型
    fontStyle: 'fill',      //字体绘制方法，有fill和stroke
    content: 'abcdefghijklmnopqrstuvwcanvas1425369870',  //验证码内容
    length: 4    //验证码长度
}); 
captcha2.draw(document.querySelector('#captcha1'),function(r){
    console.log(r);
    count=r
})




//当点击注册账号的后进行轻验证
loginBtn.addEventListener('click',function(){
    console.log(15269);


    //获取输入框里面的值
    const loginPhoneVal=loginPhone.value
    const loginYanzhengVal=loginYanzheng.value
    const loginPwdVal=loginPwd.value
    const loginPwd2Val=loginPwd2.value

    //正则表达式验证

    if(!/^1[3-9][0-9]{9}$/.test(loginPhoneVal)){  //验证手机号
        judge.textContent='手机号不正确'
        return

        }else if(loginYanzhengVal  != count){
            judge.textContent='验证码不正确'
            return

        }else if(!/^[a-zA-Z]\w{5,11}$/.test(loginPwdVal)){  //密码
            judge.textContent='密码输入不正确'
            return
            
        }else if(loginPwdVal !=loginPwd2Val){  //再次验证密码
            judge.textContent='两次密码不一致'
            return
            
        }else{
            //清除验证
            judge.textContent=''

            axios.post('http://139.9.177.51:8099/users/add',{
                account:loginPhoneVal,
                password:loginPwdVal
            }).then(function(res){

                console.log(res);
                if(res.data.status===0){
                    //弹出轻提示表示正确
                weui.toast('注册成功',{
                    duration:1000,
                    callback:function(){
                        //注册成功提示
                    location.href='./pwdLogin.html'
                    loginPhoneVal=loginPwdVal=''

                    }
                })
                
            }else{
                //出现轻提示
                weui.alert(res.data.msg)
            }

            })

        }

})

})



